import sqlite3
from PySide6.QtWidgets import (QDialog, QVBoxLayout, QCheckBox, QPushButton, 
                              QDialogButtonBox, QScrollArea, QWidget)
from PySide6.QtCore import Qt

class ColumnSelectionDialog(QDialog):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setWindowTitle("选择显示列")
        self.setMinimumWidth(300)
        
        # 创建主布局
        layout = QVBoxLayout(self)
        
        # 创建滚动区域
        scroll = QScrollArea()
        scroll_widget = QWidget()
        scroll_layout = QVBoxLayout(scroll_widget)
        
        # 定义可选列
        self.columns = [
            ("vendor", "厂商"),
            ("device_type", "设备类型"),
            ("model", "型号"),
            ("host", "主机名"),
            ("ip", "IP地址"),
            ("remote_type", "远程类型"),
            ("protocol", "协议"),
            ("port", "端口"),
            ("username", "用户名"),
            ("password", "密码"),
            ("enable_password", "Enable密码"),
            ("online", "在线状态"),
            ("version", "版本"),
            ("cpu", "CPU"),
            ("memory", "内存"),
            ("uptime", "启动时长"),
            ("fan", "风扇"),
            ("power", "电源"),
            ("temperature", "温度"),
            ("update_time", "更新时间")
        ]
        
        # 创建复选框
        self.checkboxes = {}
        for key, label in self.columns:
            checkbox = QCheckBox(label)
            checkbox.setChecked(True)  # 默认全选
            self.checkboxes[key] = checkbox
            scroll_layout.addWidget(checkbox)
        
        # 设置滚动区域
        scroll_widget.setLayout(scroll_layout)
        scroll.setWidget(scroll_widget)
        scroll.setWidgetResizable(True)
        layout.addWidget(scroll)
        
        # 添加全选/取消全选按钮
        select_all_btn = QPushButton("全选")
        select_all_btn.clicked.connect(self.select_all)
        layout.addWidget(select_all_btn)
        
        deselect_all_btn = QPushButton("取消全选")
        deselect_all_btn.clicked.connect(self.deselect_all)
        layout.addWidget(deselect_all_btn)
        
        # 添加确定/取消按钮
        button_box = QDialogButtonBox(
            QDialogButtonBox.Ok | QDialogButtonBox.Cancel
        )
        button_box.accepted.connect(self.accept)
        button_box.rejected.connect(self.reject)
        layout.addWidget(button_box)
    
    def select_all(self):
        """全选所有列"""
        for checkbox in self.checkboxes.values():
            checkbox.setChecked(True)
    
    def deselect_all(self):
        """取消全选"""
        for checkbox in self.checkboxes.values():
            checkbox.setChecked(False)
    
    def get_selected_columns(self):
        """获取选中的列"""
        return {key: checkbox.isChecked() 
                for key, checkbox in self.checkboxes.items()}

def save_column_selection(settings):
    """保存列选择设置"""
    pass  # 实现保存逻辑

def load_column_selection(settings):
    """加载列选择设置"""
    pass  # 实现加载逻辑
